home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / Main.as < prev    next >
Text File  |  2013-04-24  |  9KB  |  309 lines

  1. class Main extends State
  2. {
  3.    static var PACKAGING_SECTION = "Packaging";
  4.    static var GAME_SECTION = "Game";
  5.    static var sSTATE_INIT = "Init";
  6.    static var sSTATE_PACKAGING = "Packaging";
  7.    static var sSTATE_GAME = "Game";
  8.    static var sSTATE_WIN = "WinScreen";
  9.    static var sSTATE_LOSE = "LoseScreen";
  10.    static var sSTATE_RESET = "Reset";
  11.    static var sSTATE_INSTRUCTIONS = "Instructions";
  12.    static var nFRAME_RATE = 35;
  13.    function Main(_mcRef)
  14.    {
  15.       super(_mcRef,false);
  16.       Stage.showMenu = false;
  17.       Main.oRef = this;
  18.       this.mcRef.onEnterFrame = Delegate.create(this,this.enterFrame);
  19.       this.sSection = Main.PACKAGING_SECTION;
  20.       this.oController = new Controller(this.mcRef);
  21.       this.oDynamicPack = null;
  22.       this.bQuitting = false;
  23.       this.bFinished = false;
  24.       this.bCheatClothesActivated = false;
  25.       this.bMustSendScore = false;
  26.       this.bEasterEgg = false;
  27.       this.oShadow = new Shadow(this.mcRef.mcShadow);
  28.       this.sState = Main.sSTATE_INIT;
  29.       this.oController.playMusicLoop(Main.PACKAGING_SECTION);
  30.    }
  31.    function doHide()
  32.    {
  33.       this.mcRef.visible = false;
  34.    }
  35.    function doShow()
  36.    {
  37.       this.mcRef.visible = true;
  38.    }
  39.    function winGame()
  40.    {
  41.       this.bFinished = true;
  42.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  43.       if(CTRLGame.getRef().Level == CTRLGame.nLEVEL1)
  44.       {
  45.          this.calculateScore();
  46.          this.oController.goToNewLevel(this.game.Screen.getInterface().mcRef.mcSongs._currentframe);
  47.       }
  48.       else
  49.       {
  50.          this.oController.goTo(Main.sSTATE_WIN,this);
  51.       }
  52.    }
  53.    function loseGame()
  54.    {
  55.       this.bFinished = true;
  56.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  57.       this.oController.goTo(Main.sSTATE_LOSE,this);
  58.    }
  59.    function startNewLevel()
  60.    {
  61.       this.bFinished = false;
  62.       var _loc2_ = CTRLGame.getRef().Level;
  63.       var _loc3_ = CTRLGame.getRef().Score;
  64.       this.game.cleanUp();
  65.       delete this.game;
  66.       this.game = null;
  67.       this.game = new CTRLGame(this.mcRef.mcState,_loc3_,_loc2_ + 1);
  68.       this.game.Screen.getInterface().doShow();
  69.    }
  70.    function updateScoreField()
  71.    {
  72.       if(this.sState == Main.sSTATE_GAME)
  73.       {
  74.          CTRLGame.getRef().Screen.getInterface().setScoreValue(CTRLGame.getRef().Score);
  75.       }
  76.       else if(this.sState == Main.sSTATE_WIN || this.sState == Main.sSTATE_LOSE)
  77.       {
  78.          this.mcRef.mcState.txtScore.text = Utils.styleNumber(CTRLGame.getRef().Score);
  79.       }
  80.    }
  81.    function doPause()
  82.    {
  83.    }
  84.    function doUnPause()
  85.    {
  86.    }
  87.    function onRestartButton()
  88.    {
  89.       this.resetForNewGame();
  90.       this.sStartDynamic = ScrollingPanel.sSTATE_TITLE;
  91.       this.oController.goTo(Main.sSTATE_PACKAGING,this);
  92.    }
  93.    function onHighScoresButton()
  94.    {
  95.       if(this.sState != Main.sSTATE_PACKAGING)
  96.       {
  97.          this.resetForNewGame();
  98.       }
  99.       this.bMustSendScore = false;
  100.       this.sStartDynamic = ScrollingPanel.sSTATE_HIGHSCORES;
  101.       this.oController.goTo(Main.sSTATE_PACKAGING,this);
  102.    }
  103.    function rollOverButton()
  104.    {
  105.       this.oController.playRollOverSound();
  106.    }
  107.    function clickPlayButton()
  108.    {
  109.       this.oController.playClickSound();
  110.       this.oController.goTo(Main.sSTATE_GAME,this);
  111.    }
  112.    function clickInstructionsButton()
  113.    {
  114.       this.oController.playClickSound();
  115.       this.oController.goTo(Main.sSTATE_INSTRUCTIONS,this);
  116.    }
  117.    function clickMenuButton()
  118.    {
  119.       this.oController.playClickSound();
  120.       this.oController.getMenu().doShow();
  121.    }
  122.    function clickQuitButton()
  123.    {
  124.       this.oController.playClickSound();
  125.       this.bQuitting = true;
  126.       this.loseGame();
  127.    }
  128.    function clickSubmitScore()
  129.    {
  130.       this.oController.playClickSound();
  131.       this.bMustSendScore = true;
  132.       this.resetForNewGame();
  133.       this.sStartDynamic = ScrollingPanel.sSTATE_HIGHSCORES;
  134.       this.oController.goTo(Main.sSTATE_PACKAGING,this);
  135.    }
  136.    function clickRestartButton()
  137.    {
  138.       this.oController.playClickSound();
  139.       this.onRestartButton();
  140.    }
  141.    function clickHighScoresButton()
  142.    {
  143.       this.oController.playClickSound();
  144.       this.onHighScoresButton();
  145.    }
  146.    function setState(_sState)
  147.    {
  148.       this.sLastState = this.sState;
  149.       super.setState(_sState);
  150.       this.initState(_sState);
  151.    }
  152.    function showHighScoreStuff(_btnSubmit)
  153.    {
  154.       _global.HS.initHiScores();
  155.       if(_global.gProxyObj.getIsLoggedIn())
  156.       {
  157.          _btnSubmit._visible = true;
  158.       }
  159.       else
  160.       {
  161.          _btnSubmit._visible = false;
  162.       }
  163.       if(_global.HS.G_ShowHighScore == false)
  164.       {
  165.          _btnSubmit._visible = false;
  166.          _btnSubmit._visible = false;
  167.       }
  168.    }
  169.    function setCheatClothes(_bActive)
  170.    {
  171.       this.bCheatClothesActivated = _bActive;
  172.    }
  173.    function setMustSendScore(_bMustSend)
  174.    {
  175.       this.bMustSendScore = _bMustSend;
  176.    }
  177.    function isCheatClothesActivated()
  178.    {
  179.       return this.bCheatClothesActivated;
  180.    }
  181.    function getSection()
  182.    {
  183.       return this.sSection;
  184.    }
  185.    function get Finished()
  186.    {
  187.       return this.bFinished;
  188.    }
  189.    function get MustSendScore()
  190.    {
  191.       return this.bMustSendScore;
  192.    }
  193.    function get EasterEgg()
  194.    {
  195.       return this.bEasterEgg;
  196.    }
  197.    function setEasterEgg(_bEasterEgg)
  198.    {
  199.       this.bEasterEgg = _bEasterEgg;
  200.    }
  201.    static function getRef()
  202.    {
  203.       return Main.oRef;
  204.    }
  205.    function Init()
  206.    {
  207.       if(this.mcRef.mcState.mcLoading._currentframe == this.mcRef.mcState.mcLoading._totalframes)
  208.       {
  209.          this.setState(Main.sSTATE_PACKAGING);
  210.          this.sStartDynamic = ScrollingPanel.sSTATE_TITLE;
  211.       }
  212.    }
  213.    function Packaging()
  214.    {
  215.    }
  216.    function Game()
  217.    {
  218.       if(Controller.getRef().isPaused() || CTRLGame.getRef().Screen.isInMiniGame())
  219.       {
  220.          if(!this.oShadow.isVisible())
  221.          {
  222.             this.oShadow.doShow();
  223.          }
  224.       }
  225.       else if(this.oShadow.isVisible())
  226.       {
  227.          this.oShadow.doHide();
  228.       }
  229.    }
  230.    function LoseScreen()
  231.    {
  232.    }
  233.    function WinScreen()
  234.    {
  235.    }
  236.    function calculateScore()
  237.    {
  238.       if(!this.bQuitting)
  239.       {
  240.          var _loc2_ = CTRLGame.getRef().Songs / Main.nFRAME_RATE;
  241.          if(_loc2_ - Math.round(_loc2_) != 0)
  242.          {
  243.             _loc2_ = Math.round(_loc2_);
  244.             _loc2_ = _loc2_ + 1;
  245.          }
  246.          else
  247.          {
  248.             _loc2_ = Math.round(_loc2_);
  249.          }
  250.          CTRLGame.getRef().addToScore(_loc2_ * LD.nSECOND_LEFT_VALUE);
  251.       }
  252.    }
  253.    function initState(_sState)
  254.    {
  255.       switch(_sState)
  256.       {
  257.          case Main.sSTATE_PACKAGING:
  258.             if(this.sLastState == Main.sSTATE_INIT)
  259.             {
  260.                this.oDynamicPack = new DynamicPack(this.mcRef.mcState,DynamicPack.sSTATE_ENTER,this.sStartDynamic);
  261.             }
  262.             else
  263.             {
  264.                this.oDynamicPack = new DynamicPack(this.mcRef.mcState,DynamicPack.sSTATE_IDLE,this.sStartDynamic);
  265.             }
  266.             break;
  267.          case Main.sSTATE_GAME:
  268.             if(this.sSection == Main.PACKAGING_SECTION)
  269.             {
  270.                this.oDynamicPack.cleanUp();
  271.                delete this.oDynamicPack;
  272.                this.oDynamicPack = null;
  273.                this.game = new CTRLGame(this.mcRef.mcState,0,1);
  274.                this.oController.playMusicLoop(Main.GAME_SECTION);
  275.                Controller.getRef().getStartPop().doInstantShow();
  276.             }
  277.             this.sSection = Main.GAME_SECTION;
  278.             break;
  279.          case Main.sSTATE_WIN:
  280.             CTRLGame.getRef().addToScore(LD.nWIN_BONUSPOINTS);
  281.          case Main.sSTATE_LOSE:
  282.             this.calculateScore();
  283.             this.oController.playMusicLoop(Main.PACKAGING_SECTION);
  284.             this.sSection = Main.PACKAGING_SECTION;
  285.             this.oEndScreen = new EndScreen(this.mcRef.mcState);
  286.             CTRLGame.getRef().Screen.getInterface().doHide();
  287.             this.oController.getMenu().doInstantHide();
  288.             this.oShadow.doInstantHide();
  289.       }
  290.    }
  291.    function enterFrame()
  292.    {
  293.       MainBroadcaster.Instance.doAction();
  294.       Broadcaster.Instance.doAction();
  295.    }
  296.    function resetForNewGame()
  297.    {
  298.       Broadcaster.Instance.flushBroadcaster();
  299.       this.oEndScreen.cleanUp();
  300.       delete this.oEndScreen;
  301.       this.oController.resetForNewGame();
  302.       this.game.cleanUp();
  303.       delete this.game;
  304.       this.game = null;
  305.       this.bQuitting = false;
  306.       this.bFinished = false;
  307.    }
  308. }
  309.